﻿using System.Data.Entity;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Transport.Data;
using Transport.Infrastructure.Security;
using Transport.Infrastructure.Services;
using Transport.Infrastructure.Unity;
using Transport.Services;
using Transport.Services.ContentManagement;
using Transport.Services.Customers;
using Transport.Services.Infrastructure;
using Transport.Services.Parcels;
using Transport.Services.Settings;
using Transport.Services.Users;
namespace Transport
{
    public class UnityConfiguration
    {
        public static void Setup()
        {
            // register object lifetime
            MvcUnityContainer.Container = new UnityContainer()
                // Dbcontext
                .RegisterTypeForHttpContext<DbContext, TransportContext>()
                .RegisterTypeForHttpContext<IUnitOfWork, UnitOfWork>()
                // Repositories
                .RegisterTypeForHttpContext<IRoleRepository, RoleRepository>()
                .RegisterTypeForHttpContext<IUserRepository, UserRepository>()
                .RegisterTypeForHttpContext<INewsCategoryItemRepository, NewsCategoryItemRepository>()
                .RegisterTypeForHttpContext<INewsItemRepository, NewsItemRepository>()
                .RegisterTypeForHttpContext<IStaticPageRepository, StaticPageRepository>()
                .RegisterTypeForHttpContext<IMyOfficeRepository, MyOfficeRepository>()
                .RegisterTypeForHttpContext<IPostOfficeRepository, PostOfficeRepository>()
                .RegisterTypeForHttpContext<IRateMappingRepository, RateMappingRepository>()
                .RegisterTypeForHttpContext<IRatesTableRepository, RatesTableRepository>()
                .RegisterTypeForHttpContext<IStateProvinceRepository, StateProvinceRepository>()
                .RegisterTypeForHttpContext<ICustomerLogoRepository, CustomerLogoRepository>()
                .RegisterTypeForHttpContext<ITrackingRepository, TrackingRepository>()
                .RegisterTypeForHttpContext<IParcelRepository, ParcelRepository>()
                .RegisterTypeForHttpContext<ICustomerRepository, CustomerRepository>()
                .RegisterTypeForHttpContext<IRegionRepository, RegionRepository>()
                .RegisterTypeForHttpContext<IParcelDeliveryRepository, ParcelDeliveryRepository>()
                .RegisterTypeForHttpContext<IParcelDeliveryGroupRepository, ParcelDeliveryGroupRepository>()
                .RegisterTypeForHttpContext<IStateProvinceBelongToRegionRepository, StateProvinceBelongToRegionRepository>()
                .RegisterTypeForHttpContext<IParcelPackagingItemRepository, ParcelPackagingItemRepository>()
                .RegisterTypeForHttpContext<IParcelPackagingGroupRepository, ParcelPackagingGroupRepository>()
                //Services
                .RegisterTypeForHttpContext<IMailServerService, MailServerService>()
                .RegisterTypeForHttpContext<IParcelService, ParcelService>()
                .RegisterTypeForHttpContext<IPermissionService, PermissionService>()
                .RegisterTypeForHttpContext<IParcelDeliveryService, ParcelDeliveryService>()
                .RegisterTypeForHttpContext<ICacheManager, MemoryCacheManager>()
                ;
            
            ControllerBuilder.Current.SetControllerFactory(typeof(UnityControllerFactory));
        }
    }
}